//WdgCheckBox.cpp
/*    widgetpp - A simple C++ wrapper of DISLIN graphic library               */
/*                                                                            */
/*    Copyright (C) 2012  Mirko Cambi (email: mirko.cambi@gmail.com)          */
/*                                                                            */
/*    This program is free software: you can redistribute it and/or modify    */
/*    it under the terms of the GNU General Public License as published by    */
/*    the Free Software Foundation, either version 3 of the License, or       */
/*    (at your option) any later version.                                     */
/*                                                                            */
/*    This program is distributed in the hope that it will be useful,         */
/*    but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
/*    GNU General Public License for more details.                            */
/*                                                                            */
/*    You should have received a copy of the GNU General Public License       */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>.   */

#include "WdgCheckBox.hpp"
#include <boost/tokenizer.hpp>
#include "dislin.h"

using namespace wdgpp;

WdgCheckBox::WdgCheckBox(const std::string &lis, int sel): _lis(lis), _sel(sel)
{
   typedef boost::tokenizer<boost::char_separator<char> > tokenizer;

   boost::char_separator<char> sep("|");
   tokenizer tokens(_lis, sep);
   for(tokenizer::iterator iter = tokens.begin(); iter != tokens.end(); ++iter)
      _list.push_back(*iter);
}

int WdgCheckBox::create(int ip)
{
   return wgbox(ip, _lis.c_str(), _sel);
}

int WdgCheckBox::get_index() const
{
   return gwgbox(get_id()) - 1;
}

void WdgCheckBox::set_index(int sel)
{
   swgbox(get_id(), _sel = sel);
}

std::string WdgCheckBox::get_selected() const
{
   return _list[get_index()];
}

